//
//  SportCollectionViewCell.m
//  MansApp
//
//  Created by lanou3g on 15/7/13.
//  Copyright (c) 2015年 ACH. All rights reserved.
//

#import "SportCollectionViewCell.h"
#import "SportModel.h"
@implementation SportCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0,0, kWidth, kP6Height(70))];
        
        self.headImageView.image = [UIImage imageNamed:@"8-1"];
        self.lonelyImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, self.headImageView.bounds.size.height, kWidth, kP6Height(210))];
        self.lonelyImageView.userInteractionEnabled = YES;
        self.lonelyImageView.contentMode = UIViewContentModeTop;
        self.lonelyImageView.clipsToBounds = YES;
        
        self.lonelyIVLabel = [[UILabel alloc]initWithFrame:CGRectMake(kP6width(10), kP6Height(180), kWidth - kP6width(20), kP6Height(20))];
        
        self.lonelyIVLabel.font = [UIFont fontWithName:@"Arial-BoldItalicMT" size:17];
        self.lonelyIVLabel.textColor = [UIColor whiteColor];
        self.lonelyIVLabel.shadowColor = [UIColor blackColor];
        
        [self.lonelyImageView addSubview:self.lonelyIVLabel];
        
        self.onePieceView = [[SportPieceView alloc]initWithFrame:CGRectMake(0, self.lonelyImageView.frame.origin.y + self.lonelyImageView.bounds.size.height, kWidth / 2, kP6Height(105))];
        self.onePieceView.tag = 101;
        
        self.twoPieceView  = [[SportPieceView alloc]initWithFrame:CGRectMake(kWidth / 2,self.lonelyImageView.frame.origin.y + self.lonelyImageView.bounds.size.height, kWidth / 2, kP6Height(105))];
        self.twoPieceView.tag = 102;
        
        self.threePieceView = [[SportPieceView alloc]initWithFrame:CGRectMake(0, self.onePieceView.frame.origin.y + self.onePieceView.bounds.size.height, kWidth / 2, kP6Height(105))];
        self.threePieceView.tag = 103;
        
        self.fourPieceView = [[SportPieceView alloc]initWithFrame:CGRectMake(kWidth / 2, self.onePieceView.frame.origin.y + self.onePieceView.bounds.size.height, kWidth / 2, kP6Height(105))];
        self.fourPieceView.tag = 104;
        
        self.longPieceView = [[SportPieceView alloc]initWithFrame:CGRectMake(0, self.threePieceView.frame.origin.y + self.threePieceView.bounds.size.height, kWidth, kP6Height(110))];
        self.longPieceView.tag = 105;
        
        self.lineView1 = [[UIView alloc]initWithFrame:CGRectMake(kWidth / 2,self.lonelyImageView.frame.origin.y + self.lonelyImageView.bounds.size.height, 0.5, kP6Height(210))];
        self.lineView2 = [[UIView alloc]initWithFrame:CGRectMake(0,  self.onePieceView.frame.origin.y + self.onePieceView.bounds.size.height, kWidth, 0.5)];
        self.lineView3 = [[UIView alloc]initWithFrame:CGRectMake(0, self.threePieceView.frame.origin.y + self.threePieceView.bounds.size.height, kWidth, 0.5)];
        self.lineView1.backgroundColor = [UIColor colorWithRed:105 / 255.0 green:105/ 255.0 blue:105 / 255.0 alpha:0.8];
        
        self.lineView2.backgroundColor = [UIColor colorWithRed:105 / 255.0 green:105 / 255.0 blue:105 / 255.0 alpha:0.8];
        self.lineView3.backgroundColor = [UIColor colorWithRed:105 / 255.0 green:105 / 255.0 blue:105 / 255.0 alpha:0.8];
        [self.contentView addSubview:self.lineView1];
        [self.contentView addSubview:self.lineView2];
        [self.contentView addSubview:self.lineView3];
        
        
        [self.contentView addSubview: self.headImageView];
        [self.contentView addSubview:self.lonelyImageView];
        [self.contentView addSubview: self.onePieceView];
        [self.contentView addSubview:self.twoPieceView];
        [self.contentView addSubview: self.threePieceView];
        [self.contentView addSubview:self.fourPieceView];
        [self.contentView addSubview: self.longPieceView];
        
    }
    return self;
}


- (void)addTarget:(id)target action:(SEL)action{
    
    
    for (int i = 1; i < 6; i++) {
        SportPieceView *sView = (SportPieceView *)[self.contentView viewWithTag:100 + i];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:target action:action];
        [sView addGestureRecognizer:tap];
        
    }
    
    
    
}

- (void)setModel:(NSMutableArray *)array{
    if (array.count != 0) {
        NSMutableArray *myArr = [NSMutableArray arrayWithArray:array];
        
        SportModel *model = myArr.firstObject;
        //        int p = 0;
        //        while (model.url.length == 0 || model.url == nil) {
        //            p++;
        //            if (p >= myArr.count) {
        //                break;
        //            }
        //             model = myArr[p];
        //        }
        
        [self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.bgimage_url] placeholderImage:[UIImage imageNamed:@"page"]  completed:nil];
        
        
        [self.lonelyImageView  sd_setImageWithURL:[NSURL URLWithString:model.url] placeholderImage:[UIImage imageNamed:@"page"]];
        self.lonelyIVLabel.text = model.title;
        self.lonelyImageView.tag = [array indexOfObject:model] + 200;
        //      [myArr removeObjectAtIndex:p];
        
        for (int i = 1; i < myArr.count;i++) {
            SportModel *myModel = myArr[i];
            SportPieceView *sView = (SportPieceView *)[self.contentView viewWithTag:100 + i];
            
            
            
            sView.full_url = myModel.full_url;
            sView.titleLabel.text = myModel.title;
            sView.autherLabel.text = myModel.auther_name;
            //     sView.tag = [array  indexOfObject:myModel] + 200;
            
        }
        
    }
    
    
    
    
    
    
    
}



@end
